package com.caocaog.market.pay.syb.controller;

import com.caocaog.market.pay.syb.dto.SybDto;
import com.caocaog.market.pay.syb.service.ISybPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@Api(tags = "通联支付")
@RestController
@RequiredArgsConstructor
@RequestMapping("/sybPay")
public class SybPayController {
    private final ISybPayService sybPayService;

    /**
     * 通联支付统一支付接口
     */
    @ApiOperation(value = "通联支付-统一支付接口", notes = "通联支付-统一支付接口")
    @RequestMapping(value = "/pay", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "trxAmt", value = "交易金额", required = true),
            @ApiImplicitParam(name = "payType", value = "交易方式,W01:微信扫码支付,W02:微信JS支付,W06:微信小程序支付,A01:支付宝扫码支付,A02:支付宝JS支付,A03:支付宝APP支付,Q01:手机QQ扫码支付,Q02:手机QQ JS支付,U01:银联扫码支付(CSB),U02:银联JS支付", required = true),
    })
    public Map<String,String> pay(@RequestBody SybDto sybDto) throws Exception {
        return this.sybPayService.pay(sybDto);
    }

    /**
     * 通联支付交易关闭
     */
    @ApiOperation(value = "通联支付-交易关闭接口", notes = "通联支付-交易关闭接口")
    @RequestMapping(value = "/close", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "oldReqSn", value = "原交易单号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "oldTrxId", value = "原交易流水", required = true, dataType = "String")
    })
    public Map<String,String> close(@RequestBody SybDto sybDto) throws Exception {
        return this.sybPayService.close(sybDto);
    }


    /**
     * 通联支付交易撤销接口
     */
    @ApiOperation(value = "通联支付-交易撤销接口", notes = "通联支付-交易撤销接口")
    @RequestMapping(value = "/cancel", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "trxAmt", value = "交易金额,单位为分", required = true, dataType = "String"),
            @ApiImplicitParam(name = "payType", value = "交易方式", required = true, dataType = "String"),
            @ApiImplicitParam(name = "reqSn", value = "商户交易单号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "termInfo", value = "终端信息,json字符串格式:{termNo:终端号,deviceType:设备类型}", required = true, dataType = "String")
    })
    public Map<String,String> cancel(@RequestBody SybDto sybDto) throws Exception {
        return this.sybPayService.cancel(sybDto);
    }

    /**
     * 通联支付交易退款接口
     */
    @ApiOperation(value = "通联支付-交易退款接口", notes = "通联支付-交易退款接口")
    @RequestMapping(value = "/refund", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reqSn", value = "商户交易单号", required = true, dataType = "String")
    })
    public Map<String,String> refund(@RequestBody SybDto sybDto) throws Exception {
        sybDto.setOldReqSn(sybDto.getReqSn());
        return this.sybPayService.refund(sybDto);
    }

    /**
     * 通联支付交易查询
     */
    @ApiOperation(value = "通联支付-交易查询接口", notes = "通联支付-交易查询接口")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reqSn", value = "商户交易单号", required = true, dataType = "String")
    })
    public Map<String,String> query(@RequestBody SybDto sybDto) throws Exception {
        return this.sybPayService.query(sybDto);
    }


}
